home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / tcp / AmigaTCP.lha / AmigaTCP / src / hexload.c < prev    next >
C/C++ Source or Header  |  1989-06-24  |  3KB  |  114 lines

  1. /*
  2.  *  Hex loader program.  Sends an ASCII file out the serial port to the
  3.  *  loader running in the TNC-2 KISS loader ROM.  Use this rather than
  4.  *  just "COPY TNC2KISS.HEX to SER:" so we don't have to depend on what
  5.  *  the preferences baud rate for the serial port is set to.
  6.  *
  7.  *  Copyright (C) 1987
  8.  *  Louis A. Mamakos
  9.  *
  10.  *  For non-commercial use only.  May not be sold, or included in any other
  11.  *  product or collection of software that is sold for profit.
  12.  */
  13.  
  14. #include <exec/types.h>
  15. #include <functions.h>        /* for Manx Aztec C, get func returns */
  16. #include <exec/nodes.h>
  17. #include <exec/lists.h>
  18. #include <exec/ports.h>
  19. #include <exec/devices.h>
  20. #include <exec/io.h>
  21. #include <devices/serial.h>
  22. #include <libraries/dos.h>
  23. #include <libraries/dosextens.h>
  24. #include <stdio.h>
  25.  
  26. #ifndef    DEFFILE
  27. #define    DEFFILE    "tnc2kiss.hex"
  28. #endif
  29.  
  30. #ifndef    DEFBAUD
  31. #define    DEFBAUD    4800
  32. #endif
  33.  
  34. struct IOExtSer serout;
  35. struct MsgPort *seroutp;
  36. struct    FileHandle    *hexfile;
  37. char    buffer[500];
  38. extern    int Enable_Abort;
  39. int    baud = DEFBAUD;
  40.  
  41. main(argc, argv)
  42.     int argc;
  43.     char **argv;
  44. {
  45.     register long totlen = 0;
  46.     register long len;
  47.     
  48.     strcpy(buffer, DEFFILE);
  49.     if ((argc > 1) && ((baud = atoi(argv[1])) > 0)) {
  50.         serout.io_Baud = baud;
  51.         argc--; argv++;
  52.         printf("Loading at %d baud\n", baud);
  53.     }
  54.     if (argc > 1)
  55.         strcpy(buffer, argv[1]);
  56.  
  57.     hexfile = Open(buffer, MODE_OLDFILE);
  58.  
  59.     Enable_Abort = 0;
  60.  
  61.     if (hexfile == 0L) {
  62.         printf("Can't open file '%s'\n", buffer);
  63.         exit(1);
  64.     }
  65.  
  66.     if ((seroutp = CreatePort(0L, 0L)) == NULL) {
  67.         printf("Can't create serial input port");
  68.         Close(hexfile);
  69.         exit(2);
  70.     }
  71.     /*
  72.      * Open serial device.
  73.      */
  74.     serout.io_SerFlags = SERF_XDISABLED | SERF_RAD_BOOGIE;  /* ? */
  75.     serout.io_Status = 0;
  76.     serout.io_Baud = baud;
  77.     if (OpenDevice("serial.device", 0L, &serout, 0L) != 0) {
  78.         printf("Can't open serial device");
  79.         DeletePort(seroutp);
  80.         Close(hexfile);
  81.         exit(2);
  82.     }
  83.     serout.IOSer.io_Message.mn_ReplyPort = seroutp;
  84.     serout.IOSer.io_Data = (APTR) buffer;
  85.     serout.IOSer.io_Length = 0;
  86.     serout.IOSer.io_Command = CMD_WRITE;
  87.     serout.IOSer.io_Flags = 0;
  88.     serout.io_SerFlags = SERF_XDISABLED | SERF_RAD_BOOGIE;
  89.     serout.io_Baud = baud;
  90.     serout.IOSer.io_Command = SDCMD_SETPARAMS;
  91.  
  92.     if (DoIO(&serout))
  93.         printf("SETPARMS failed\n");
  94.  
  95.     serout.IOSer.io_Command = CMD_WRITE;
  96.     serout.IOSer.io_Data = (APTR) buffer;
  97.     while ((len = Read(hexfile, buffer, (ULONG) sizeof(buffer))) > 0) {
  98.         serout.IOSer.io_Length = len;
  99.         if (DoIO(&serout))
  100.             printf("Serial write failed %ld\n",
  101.                 serout.IOSer.io_Error);
  102.         totlen += len;
  103.         if (Chk_Abort()) {
  104.             printf("Hex load aborted!\n");
  105.             break;
  106.         }
  107.     }
  108.     printf("Wrote %ld bytes\n", totlen);
  109.     Close(hexfile);
  110.     CloseDevice(&serout);
  111.     DeletePort(seroutp);
  112. }
  113.  
  114.